package org.gnyxy.controller.front;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.gnyxy.result.Result;
import org.gnyxy.service.MaterialService;
import org.gnyxy.vo.MaterialUserVO;
import org.gnyxy.vo.MaterialVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.util.List;

@RestController("UserMaterialController")
@RequestMapping("/front/material")
@Slf4j
@Api(tags = "小程序端-菜品原材料查看")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    /**
     * 获取所有菜品原材料(配菜)
     * @return
     */
    @GetMapping("/getAll")
    @ApiOperation("获取所有菜品原材料(配菜)")
    @Cacheable(cacheNames = "materialsCache", key = "'AllMaterials'")
    public Result<List<MaterialUserVO>> getAll(){
        log.info("获取所有菜品原材料(配菜)");
        List<MaterialUserVO> materialUserVOS = materialService.getAll();
        return Result.success(materialUserVOS);
    }

    /**
     * 根据名称查找菜品原材料
     * @param name
     * @return
     */
    @GetMapping("/{name}")
    @ApiOperation("根据名称查找菜品原材料")
    public Result<List<MaterialUserVO>> getByName(@PathVariable String name){
        log.info("根据名称：{} 查找菜品原材料",name);
        List<MaterialUserVO> materialUserVOS = materialService.getTrueStatusByName(name);
        return Result.success(materialUserVOS);
    }

    @GetMapping("/getById/{id}")
    @ApiOperation("根据id查看食材详情")
    public Result<MaterialUserVO> getById(@PathVariable Long id){
        log.info("根据id:{}查找菜品原材料",id);
        MaterialUserVO materialUserVO = materialService.getTureStatusById(id);
        return Result.success(materialUserVO);
    }

}
